home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbbook13 / vbbinp13.frm < prev    next >
Text File  |  1995-05-08  |  31KB  |  889 lines

  1. VERSION 2.00
  2. Begin Form VBBinp 
  3.    BackColor       =   &H00FF8080&
  4.    Caption         =   "VB Book Input"
  5.    ClientHeight    =   5595
  6.    ClientLeft      =   1260
  7.    ClientTop       =   1545
  8.    ClientWidth     =   5640
  9.    Height          =   6000
  10.    Icon            =   VBBINP13.FRX:0000
  11.    Left            =   1200
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    ScaleHeight     =   5595
  15.    ScaleWidth      =   5640
  16.    Top             =   1200
  17.    Width           =   5760
  18.    Begin Frame Outname 
  19.       BackColor       =   &H008080FF&
  20.       Caption         =   "Output To:"
  21.       Height          =   855
  22.       Left            =   3180
  23.       TabIndex        =   11
  24.       Top             =   4560
  25.       Width           =   2235
  26.       Begin ComboBox comboutname 
  27.          BackColor       =   &H00C0C0C0&
  28.          Height          =   300
  29.          Left            =   60
  30.          TabIndex        =   8
  31.          Top             =   360
  32.          Width           =   2115
  33.       End
  34.    End
  35.    Begin DirListBox Dir1 
  36.       BackColor       =   &H00C0C0C0&
  37.       Height          =   2535
  38.       Left            =   240
  39.       TabIndex        =   6
  40.       Top             =   2880
  41.       Width           =   2895
  42.    End
  43.    Begin FileListBox File1 
  44.       BackColor       =   &H00C0C0C0&
  45.       Height          =   1980
  46.       Left            =   3720
  47.       TabIndex        =   7
  48.       Top             =   2520
  49.       Width           =   1695
  50.    End
  51.    Begin DriveListBox Drive1 
  52.       BackColor       =   &H00C0C0C0&
  53.       Height          =   315
  54.       Left            =   240
  55.       TabIndex        =   5
  56.       Top             =   2520
  57.       Width           =   2895
  58.    End
  59.    Begin CheckBox Clk6 
  60.       Caption         =   "A2 (American) Paper or A4 if off"
  61.       Height          =   255
  62.       Left            =   360
  63.       TabIndex        =   15
  64.       Top             =   2040
  65.       Value           =   1  'Checked
  66.       Width           =   3255
  67.    End
  68.    Begin ComboBox Linelength 
  69.       BackColor       =   &H00C0C0C0&
  70.       Height          =   300
  71.       Left            =   4260
  72.       TabIndex        =   13
  73.       Top             =   1740
  74.       Width           =   1035
  75.    End
  76.    Begin CheckBox clk5 
  77.       Caption         =   "Set Line Wrap On"
  78.       Height          =   255
  79.       Left            =   360
  80.       TabIndex        =   4
  81.       Top             =   1680
  82.       Value           =   1  'Checked
  83.       Width           =   3255
  84.    End
  85.    Begin TextBox Text1 
  86.       BackColor       =   &H00FF8080&
  87.       BorderStyle     =   0  'None
  88.       Enabled         =   0   'False
  89.       Height          =   195
  90.       Left            =   4260
  91.       MultiLine       =   -1  'True
  92.       TabIndex        =   14
  93.       Text            =   "Text Width:"
  94.       Top             =   1500
  95.       Width           =   1035
  96.    End
  97.    Begin CheckBox clk4 
  98.       Caption         =   "Use Speaker"
  99.       Height          =   255
  100.       Left            =   360
  101.       TabIndex        =   3
  102.       Top             =   1320
  103.       Value           =   1  'Checked
  104.       Width           =   3255
  105.    End
  106.    Begin CheckBox clk3 
  107.       Caption         =   "Print Page Numbers"
  108.       Height          =   255
  109.       Left            =   360
  110.       TabIndex        =   2
  111.       Top             =   960
  112.       Value           =   1  'Checked
  113.       Width           =   3255
  114.    End
  115.    Begin PictureBox Picture1 
  116.       BackColor       =   &H00FF8080&
  117.       Height          =   495
  118.       Left            =   4500
  119.       Picture         =   VBBINP13.FRX:0302
  120.       ScaleHeight     =   465
  121.       ScaleWidth      =   465
  122.       TabIndex        =   12
  123.       Top             =   660
  124.       Width           =   495
  125.    End
  126.    Begin CheckBox clk2 
  127.       Caption         =   "Print Date/Time on each Page"
  128.       Height          =   255
  129.       Left            =   360
  130.       TabIndex        =   1
  131.       Top             =   600
  132.       Value           =   1  'Checked
  133.       Width           =   3255
  134.    End
  135.    Begin CommandButton go 
  136.       Caption         =   "Do It"
  137.       Default         =   -1  'True
  138.       Height          =   375
  139.       Left            =   4800
  140.       TabIndex        =   9
  141.       Top             =   240
  142.       Width           =   735
  143.    End
  144.    Begin CommandButton Cancel 
  145.       Caption         =   "Cancel"
  146.       Height          =   375
  147.       Left            =   3960
  148.       TabIndex        =   10
  149.       Top             =   240
  150.       Width           =   735
  151.    End
  152.    Begin CheckBox clk1 
  153.       BackColor       =   &H00FFFFFF&
  154.       Caption         =   "Print Filename on each Page"
  155.       ForeColor       =   &H00000000&
  156.       Height          =   255
  157.       Left            =   360
  158.       TabIndex        =   0
  159.       Top             =   240
  160.       Value           =   1  'Checked
  161.       Width           =   3255
  162.    End
  163. End
  164. Dim ESC$, FF$, LF$, filename$, outfile$, NewName$, NL$
  165. Dim Page%, num$, tune%
  166. Dim PC As Flags
  167. Dim PaperAmerican
  168. Dim PaperWidth
  169. Dim ToAFile
  170. Dim LeftSide%, RightSide%, FirstPass%
  171. Dim Bookmark%, Junk%, Abort%
  172. Dim Default$, Title$, Msg$
  173.  
  174. Dim lastchange As Integer
  175.  
  176. Const fileboxclick = 0, dirsboxclick = 1
  177. Const True = -1, False = 0
  178.  
  179.  
  180.  
  181. Sub BuildArray (ptrarray&(), pgcount%)
  182.     'Was Satic Sub ...
  183.     MaxLines% = 66                                'Maximum number of lines
  184.     Offset& = 1                                   'Start of file (seek point)
  185.     Open filename$ For Binary Access Read As #1 Len = 1   'Open file to check
  186.     TotalSize& = LOF(1)                           'Get LEN of file so we don't read too far
  187.     FileLeft& = TotalSize&                        'Setup a counter to show whats left
  188.  
  189.     'FRE is not supported by VB.  Use GetFreeSpace() instead (see global module)
  190.     memAvail& = GetFreeSpace(0)        '65536  FRE(FileName$) - 2048  'Check available string memory
  191.     If memAvail& < 2048 Then Error 14             'Force out of memory error
  192.     SixteenK% = 16384
  193.  
  194.    If TotalSize& > SixteenK% Then                'Set a buffer size
  195.       If memAvail& > SixteenK% Then              'If the file is larger than 16K
  196.          BufAvail& = SixteenK%                   'Set it to 16k
  197.       Else
  198.          BufAvail& = memAvail&
  199.       End If
  200.    Else
  201.       If TotalSize& < memAvail& Then             'Otherwise set it to file size
  202.          BufAvail& = TotalSize&
  203.       End If
  204.       BuffSize% = BufAvail&
  205.    End If
  206.  
  207.    pgcount% = 1                                  'Initialize page count
  208.    ptrarray&(pgcount%) = 1                       'First pointer is always 1
  209.    LnCount% = 0                                  'Initialize line count
  210.  
  211. GetPage:                                         'Read the file
  212.                                                  
  213.   If FileLeft& < BufAvail& Then                  'Check amount left to read
  214.      Buffer$ = Space$(FileLeft&)                 'If less than our buffer, use lessor
  215.   Else
  216.      Buffer$ = Space$(BufAvail&)                 'Otherwise use full buffer size
  217.   End If
  218.  
  219.   Get #1, Offset&, Buffer$                       'Read in a buffers worth
  220.   stptr% = 1                                     'Pointer into buffer$
  221.   LastLine% = 0                                  'remember last position
  222.  
  223. PageCheck:
  224.   Junk% = DoEvents()                             'yield some time to the system
  225.   TempLn% = InStr(stptr%, Buffer$, LF$)          'Position of next linefeed
  226.   temppg% = InStr(stptr%, Buffer$, FF$)          'Position of next pagefeeds
  227.  
  228.   If temppg% Then                                'If there was a page feed
  229.      If temppg% < TempLn% Or TempLn% = 0 Then    '  was it before our linefeed?
  230.         pgcount% = pgcount% + 1                  '  yes then bump page count
  231.         ptrarray&(pgcount%) = Offset& + temppg%  '  set next array element
  232.         stptr% = temppg% + 1                     '  set instr pointer
  233.         LnCount% = 0                             '  reset linecount
  234.         If stptr% < Len(Buffer$) Then GoTo PageCheck 'and loop back for more
  235.       End If
  236.   End If
  237.  
  238.   If TempLn% Then                                'Line